import 'dart:math';

List<int> getRandomNumbers({
  required int randomNumberCount,
  required int rightNumberBoundary,
}) {
  final random = Random();
  final randomNumbers = <int>[];
  final sortedNumbers = <int>[];

  for (var i = 0; i < randomNumberCount; i++) {
    var newRandomNumber = random.nextInt(rightNumberBoundary - i);

    for (final index in sortedNumbers) {
      if (index <= newRandomNumber) {
        newRandomNumber++;
      }
    }

    randomNumbers.add(newRandomNumber);

    var j = 0;
    while (sortedNumbers.isNotEmpty &&
        j < sortedNumbers.length &&
        sortedNumbers[j] < newRandomNumber) {
      j++;
    }
    sortedNumbers.insert(j, newRandomNumber);
  }

  return randomNumbers;
}

int combinedComparator<T>({
  required T first,
  required T second,
  required List<int Function(T first, T second)> comparators,
}) {
  for (final comparator in comparators) {
    final comparisonResult = comparator(first, second);
    if (comparisonResult != 0) {
      return comparisonResult;
    }
  }
  return 0;
}
